<script setup lang='ts' name="sales-order-log">
import type { PlusColumn } from 'plus-pro-components'
import type { VxeGridListeners, VxePagerEvents, VxeTableInstance } from 'vxe-table'

import { delPrivileges } from '@fl/api/iam-api'
import { SearchForm, SearchTable } from '@fl/components'
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const schema: PlusColumn[] = [
    {
        colProps: {
            span: 6,
        },
        label: '类型',
        options: [
            {
                label: '类型',
                value: 1,
            },
        ],
        prop: 'name',
        valueType: 'select',
    },
] as const

const form = ref({
    name: '',
})

const gridOptions = reactive<any>({
    border: true,
    columns: [
        { field: 'code', title: '操作名称' },
        { field: 'description', title: '操作结果' },
        { field: 'module_name', title: '备注' },
        { field: 'a', title: '操作时间' },
        { field: 'b', title: '操作公司' },
        { field: 'b', title: '操作人' },
    ],
    data: [],
    editConfig: {
        mode: 'row',
        showStatus: true,
        trigger: 'manual',
    },
    height: 530,
    keepSource: true,
    loading: false,
    pagerConfig: {
        currentPage: 1,
        enabled: true,
        pageSize: 10,
        pageSizes: [10, 20, 50, 100, 200, 500],
        total: 0,
    },
    showOverflow: true,
})

function reset() {
    form.value.name = ''
    getData()
}

const tableRef = ref<VxeTableInstance<any>>()

async function getData() {
    // gridOptions.loading = true
    // getPrivileges({
    //     ...form.value,
    //     page: gridOptions.pagerConfig.currentPage,
    //     page_size: gridOptions.pagerConfig.pageSize,
    // }).then((res: any) => {
    //     gridOptions.pagerConfig.total = res.total ?? 0
    //     gridOptions.data = res?.items ?? []
    //     gridOptions.loading = false
    // })
    gridOptions.data = [
        {
            code: '支付',
        },
        {
            code: '接单',
        },
    ]
}
getData()

const handlePageChange: VxePagerEvents.PageChange = ({ currentPage, pageSize }) => {
    gridOptions.pagerConfig.currentPage = currentPage
    gridOptions.pagerConfig.pageSize = pageSize
    getData()
}

function goToList() {
    router.go(-1)
}
</script>

<template>
    <ElCard mb-20>
        <el-button mb-20
                   @click="goToList"
        >
            返回列表
        </el-button>

        <SearchForm v-model="form"
                    :columns="schema"
                    submit-text="查询"
                    @submit="() => getData()"
                    @reset="reset"
        />
    </ElCard>

    <ElCard>
        <SearchTable v-bind="gridOptions"
                     ref="tableRef"
                     v-model:pager="gridOptions.pagerConfig"
                     :loading="gridOptions.loading"
                     @page-change="handlePageChange"
        />
    </ElCard>
</template>
